Ask for filter specifity instead of 'match'
authorBen Wiederhake <BenWiederhake.GitHub@gmx.de>
Fri, 24 Mar 2017 21:21:29 +0000 (22:21 +0100)
committerBen Wiederhake <BenWiederhake.GitHub@gmx.de>
Mon, 10 Apr 2017 18:20:32 +0000 (20:20 +0200)
src/cargo/ops/cargo_compile.rs
src/cargo/ops/cargo_install.rs
src/cargo/ops/cargo_run.rs
src/cargo/ops/cargo_test.rs

index ca68bfe1f994184b7c5f9d94a01189d17c470fcb..1256787f4f8aa1ea12bce637ffc9db00339a0860 100644 (file)
@@ -382,6 +382,13 @@ impl<'a> CompileFilter<'a> {
             }
         }
     }
+
+    pub fn is_specific(&self) -> bool {
+        match *self {
+            CompileFilter::Everything { .. } => false,
+            CompileFilter::Only { .. } => true,
+        }
+    }
 }
 
 #[derive(Clone, Copy, Debug)]
index a802bffbae01de84d4d8dbee445753cdee67482d..d19ac402faa895e700873024206cb8c9244e57eb 100644 (file)
@@ -358,7 +358,7 @@ fn check_overwrites(dst: &Path,
                     filter: &ops::CompileFilter,
                     prev: &CrateListingV1,
                     force: bool) -> CargoResult<BTreeMap<String, Option<PackageId>>> {
-    if let CompileFilter::Everything { .. } = *filter {
+    if !filter.is_specific() {
         // If explicit --bin or --example flags were passed then those'll
         // get checked during cargo_compile, we only care about the "build
         // everything" case here
index 911b862158e2e016049b672a2150469867da27b4..47d18a981716945ea987f9973e48cb82a8341334 100644 (file)
@@ -1,6 +1,6 @@
 use std::path::Path;
 
-use ops::{self, CompileFilter, Packages};
+use ops::{self, Packages};
 use util::{self, human, CargoResult, ProcessError};
 use core::Workspace;
 
@@ -23,32 +23,27 @@ pub fn run(ws: &Workspace,
     };
 
     let mut bins = pkg.manifest().targets().iter().filter(|a| {
-        !a.is_lib() && !a.is_custom_build() && match options.filter {
-            CompileFilter::Everything { .. } => a.is_bin(),
-            CompileFilter::Only { .. } => options.filter.matches(a),
+        !a.is_lib() && !a.is_custom_build() && if !options.filter.is_specific() {
+            a.is_bin()
+        } else {
+            options.filter.matches(a)
         }
     });
     if bins.next().is_none() {
-        match options.filter {
-            CompileFilter::Everything { .. } => {
-                bail!("a bin target must be available for `cargo run`")
-            }
-            CompileFilter::Only { .. } => {
-                // this will be verified in cargo_compile
-            }
+        if !options.filter.is_specific() {
+            bail!("a bin target must be available for `cargo run`")
+        } else {
+            // this will be verified in cargo_compile
         }
     }
     if bins.next().is_some() {
-        match options.filter {
-            CompileFilter::Everything { .. } => {
-                bail!("`cargo run` requires that a project only have one \
-                       executable; use the `--bin` option to specify which one \
-                       to run")
-            }
-            CompileFilter::Only { .. } => {
-                bail!("`cargo run` can run at most one executable, but \
-                       multiple were specified")
-            }
+        if !options.filter.is_specific() {
+            bail!("`cargo run` requires that a project only have one \
+                   executable; use the `--bin` option to specify which one \
+                   to run")
+        } else {
+            bail!("`cargo run` can run at most one executable, but \
+                   multiple were specified")
         }
     }
 
index 14b813b3bec934dd7784885c36ce545df047c449..b659965d5b7832f8330a52dcb0c533d70f4dde4b 100644 (file)
@@ -20,6 +20,7 @@ pub fn run_tests(ws: &Workspace,
         return Ok(None)
     }
     let (test, mut errors) = if options.only_doc {
+        assert!(options.compile_opts.filter.is_specific());
         run_doc_tests(options, test_args, &compilation)?
     } else {
         run_unit_tests(options, test_args, &compilation)?
@@ -32,7 +33,7 @@ pub fn run_tests(ws: &Workspace,
 
     // If a specific test was requested or we're not running any tests at all,
     // don't run any doc tests.
-    if let ops::CompileFilter::Only { .. } = options.compile_opts.filter {
+    if options.compile_opts.filter.is_specific() {
         match errors.len() {
             0 => return Ok(None),
             _ => return Ok(Some(CargoTestError::new(test, errors)))